import {
  Message,
  MessageBox
} from 'element-ui'

export function validatePhone (value) {
  if (value === '') {
    Message({
      message: "请输入手机号",
      type: "warning"
    });
    return false
  } else if (!(/^1[3456789]\d{9}$/.test(value))) {
    Message({
      message: "请输入正确的手机号",
      type: "warning"
    });
    return false
  } else {
    return true
  }
}

export function ValidateinviteCode (value) {
  if (value == '') {
    Message({
      message: "请输入邀请码",
      type: "warning"
    });
    return false
  } else {
    var reg=new RegExp("^[0-9]{6}$");
    if (reg.test(value)) {
      return true
    } else {
      Message({
        message: "请输入正确的邀请码格式",
        type: "warning"
      });
      return false
    }
  }
}

export function validateName (value) {
  if (value === "") {
    Message({
      message: "请输入姓名",
      type: "warning"
    });
    return false
  } else if (!(/^[\u4e00-\u9fa5A-Za-z]+$/.test(value))) {
    Message({
      message: "请输入正确的姓名",
      type: "warning"
    });
    return false
  } else {
    return true
  }
}

export function validateCode (value) {
  if (value == '') {
    Message({
      message: "请输入验证码",
      type: "warning"
    });
    return false
  } else if (!(/^[0-9]{6}$/.test(value))) {
    Message({
      message: "请输入正确的验证码",
      type: "warning"
    });
    return false
  } else {
    return true
  }
}
export function  Validateid_card (value) {
  if (value === "" || value == undefined || value == null) {
    Message({
      message: "请输入身份证号",
      type: "warning"
    });
    return false
  } else {
    if (!(/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(value))) {
      Message({
        message: "请输入正确的身份证号",
        type: "warning"
      });
      return false
    } else {
      return true
    }
  }
}

export const validateEmail = (value) => {
	if (value === '') {
    Message({
      message: "请输入邮箱",
      type: "warning"
    });
    return false
	} else if (!(/^[A-Za-z0-9]+([_\.][A-Za-z0-9]+)*@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,6}$/.test(value))) {
    Message({
      message: "请输正确的邮箱",
      type: "warning"
    });
    return false
	} else {
    return true
	}
}

export const validateNewpwd = (newPwd,confirmPwd) => {
	if (newPwd === '') {
    Message({
      message: "填写新密码",
      type: "warning"
    });
    return false
	} else if (newPwd.length < 6 && newPwd.length > 12) {
    Message({
      message: "密码长度为6-12位",
      type: "warning"
    });
    return false
	} else if (newPwd !== confirmPwd) {
    Message({
      message: "两次密码不一致",
      type: "warning"
    });
    return false
	} else {
    return true
	}
}